package com.siyao.redvip.ui.activity;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import com.android.volley.http.RequestManager;
import com.android.volley.http.RequestMap;
import com.android.volley.http.RequestManager.RequestListener;
import com.google.gson.reflect.TypeToken;
import com.siyao.redvip.R;
import com.siyao.redvip.bean.HDxxBean;
import com.siyao.redvip.bean.Record;
import com.siyao.redvip.components.base.BaseFragmentActivity;
import com.siyao.redvip.network.NetConstans;
import com.siyao.redvip.ui.adapter.HDetailsAdapter;
import com.siyao.redvip.utils.DateTimeUtil;
import com.siyao.redvip.utils.ToastUtils;
import com.siyao.redvip.utils.Track;

/**
 * 活动信息详情
 * @author lenovo
 *
 */
public class HdxxDetailsActivity extends BaseFragmentActivity{
	
	private TextView tvOrganizationsTitle;//标题
	private TextView tvOrganizationsTime;//时间
	private TextView tvOrganizationsMainText;//内容
	private TextView itemManText ;//负责人
	private TextView itemPhoneText;//电话号码
	private TextView tvOrganizationsPlace;//电话号码
	
	private ListView imageList;//放图片的LinearLayout
	
	private List<HDxxBean> listData;//获取到的活动的信息
	
	private String hdxxId;//活动id
	private String title;
	private String content;
	private String datatime;
	private String place;
	private String manager;
	private String telephone;
	
	private Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitleText("活动详情");
		setLeftButton("返回");
		
	}
	
	@Override
	protected void beforeInit() {
		hdxxId=getIntent().getStringExtra("hdxxId");
		content=getIntent().getStringExtra("content");
		datatime=getIntent().getStringExtra("datatime");
		place=getIntent().getStringExtra("place");
		manager=getIntent().getStringExtra("manager");
		telephone=getIntent().getStringExtra("telephone");
		String flagTime=datatime.split(" ")[0];
		
		Date dBefore = new Date();
		String now=DateTimeUtil.formatDateTime(dBefore, DateTimeUtil.DF_YYYY_MM_DD);//比当天的日期顺延后2天
		
		if(flagTime.equals(now)){
			setRightButton(R.drawable.chat_img_selector);
		}
	}

	@Override
	public void ininlazeLayout() {
		View appLayout = getLayoutInflater().inflate(R.layout.activity_hdxx_details, null);
		appMainView.addView(appLayout, layoutParams);
	}
	
	@Override
	public void ininlazeView() {
		tvOrganizationsTitle=(TextView) findViewById(R.id.tv_organizations_title);
		tvOrganizationsTime=(TextView) findViewById(R.id.tv_organizations_time);
		tvOrganizationsMainText=(TextView) findViewById(R.id.tv_organizations_main_text);
		itemManText=(TextView) findViewById(R.id.item_man_text);
		itemPhoneText=(TextView) findViewById(R.id.item_phone_text);
		tvOrganizationsPlace=(TextView) findViewById(R.id.tv_organizations_place);
		imageList=(ListView) findViewById(R.id.image_list);
		
		itemPhoneText.setOnClickListener(this);
		
		tvOrganizationsTime.setText(datatime);
		tvOrganizationsMainText.setText(content);
		itemManText.setText(manager);
		itemPhoneText.setText(telephone);
		tvOrganizationsPlace.setText(place);
	}

	@Override
	public void ininlazeData() {
		RequestMap params = new RequestMap();
		params.put("activityId", hdxxId);
		RequestManager.getInstance(HdxxDetailsActivity.this).post(NetConstans.ACTIVITY_INFO, params, new RequestListener() {
			@Override
			public void onSuccess(String response, String url, int actionId) {
				Track.i("返回数据：---"+response);
				//{"total":"0","status":1,"data":[]}
				HDxxBean  hdxxBean= gson.fromJson(response, new TypeToken<HDxxBean>(){}.getType());
				if(hdxxBean.getStatus()==1){
					List<Record>  records= hdxxBean.getData();
					if(!records.isEmpty()){
						HDetailsAdapter adapter = new HDetailsAdapter(HdxxDetailsActivity.this);
						adapter.setList(records);
						imageList.setAdapter(adapter);
					}
				}else{
					ToastUtils.makeMesageShort(HdxxDetailsActivity.this, getString(R.string.server_error));
				}
			}
			@Override
			public void onRequest() {
				
			}
			@Override
			public void onError(String errorMsg, String url, int actionId) {
				ToastUtils.makeMesageShort(HdxxDetailsActivity.this, getString(R.string.server_error));
			}
		}, 2);
	}
	
	@Override
	public void onClick(View v) {
		int vid = v.getId();
		switch (vid) {
		case R.id.top_left_btn:
			intent = new Intent(this, HdxxActivity.class);
			startActivity(intent);
			finish();
			break;
			
		case R.id.top_right_btn_image:
			intent = new Intent();
			intent.putExtra("hdxxId", hdxxId);
			intent.setClass(this, PhotoActivity.class);
			startActivity(intent);
			finish();
			break;
		case R.id.item_phone_text:
			intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + telephone));
			startActivity(intent);
			break;
		default:
			break;
		}
	}
}
